﻿using Microsoft.SemanticKernel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IntermediateDemo;

internal static class PlainTextPrompt
{
    public static async Task PlainTextAsync(Kernel _kernel)
    {
        string chatPrompt = """
                        <message role="user">北京是什么?</message>
                        """;
        Console.WriteLine(await RenderPromptAsync(_kernel, new PromptTemplateConfig(chatPrompt)));
        Console.WriteLine(await _kernel.InvokePromptAsync(chatPrompt));
    }

    static readonly IPromptTemplateFactory _promptTemplateFactory = new KernelPromptTemplateFactory();

    static Task<string> RenderPromptAsync(Kernel _kernel, PromptTemplateConfig promptConfig, KernelArguments? arguments = null,
      IPromptTemplateFactory? promptTemplateFactory = null)
    {
        promptTemplateFactory ??= _promptTemplateFactory;
        var promptTemplate = promptTemplateFactory.Create(promptConfig);
        return promptTemplate.RenderAsync(_kernel, arguments);
    }
}
